Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Breaking change] Add fine field option #991

Merged
merged 73 commits into from
Jun 13, 2024

Conversation

lroberts36
Copy link
Collaborator

@lroberts36 lroberts36 commented Dec 19, 2023

PR Summary

This PR adds the new flag Metadata::Fine, which indicates that the field should have twice the resolution of default fields. Fields with this flag can exchange ghosts, and be prolongated and restricted similarly to normal fields. They can also be output, although none of the plotting scripts have been updated to deal with fine fields. This feature is in use in Assail.

PR Checklist

  • Code passes cpplint
  • New features are documented.
  • Adds tests for new features.
  • Code is formatted
  • Changes are summarized in CHANGELOG.md
  • Change is breaking (API, behavior, ...)
    • Change is additionally added to CHANGELOG.md in the breaking section
    • PR is marked as breaking
    • Short summary API changes at the top of the PR (plus optionally with an automated update/fix script)
  • CI has been triggered on Darwin for performance regression tests.
  • Docs build
  • (@lanl.gov employees) Update copyright on changed files

Copy link
Collaborator

@Yurlungur Yurlungur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well this was remarkably simple. I was expecting it to be a little more complicated than this but nice to see it worked out so easily.

example/advection/advection_package.cpp Outdated Show resolved Hide resolved
example/advection/advection_package.cpp Outdated Show resolved Hide resolved
@lroberts36
Copy link
Collaborator Author

Well this was remarkably simple. I was expecting it to be a little more complicated than this but nice to see it worked out so easily.

@Yurlungur: Well, I have only tested for unigrid so not totally sure it works for prolongation and restriction. But at least it runs with AMR w/o segfaults.

@Yurlungur
Copy link
Collaborator

Well this was remarkably simple. I was expecting it to be a little more complicated than this but nice to see it worked out so easily.

@Yurlungur: Well, I have only tested for unigrid so not totally sure it works for prolongation and restriction. But at least it runs with AMR w/o segfaults.

I suppose we should check for correctness with AMR lol.

@lroberts36 lroberts36 changed the title WIP: Add fine field option Add fine field option May 14, 2024
Copy link
Collaborator

@adamdempsey90 adamdempsey90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Downstream app looks good

doc/sphinx/src/interface/metadata.rst Outdated Show resolved Hide resolved
Co-authored-by: Adam M. Dempsey <adamdemps@gmail.com>
Copy link
Collaborator

@pgrete pgrete left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just did a quick review. I understand where this feature might be useful and just have a couple of comments regarding the current implementation.

doc/sphinx/src/interface/metadata.rst Outdated Show resolved Hide resolved
example/advection/advection_driver.cpp Outdated Show resolved Hide resolved
example/advection/advection_package.cpp Outdated Show resolved Hide resolved
src/bvals/comms/bnd_info.cpp Show resolved Hide resolved
src/outputs/output_utils.cpp Show resolved Hide resolved
src/mesh/meshblock.cpp Show resolved Hide resolved
Copy link
Collaborator

@Yurlungur Yurlungur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the new example!

example/fine_advection/advection_driver.cpp Show resolved Hide resolved
example/fine_advection/advection_driver.cpp Show resolved Hide resolved
example/fine_advection/advection_driver.cpp Show resolved Hide resolved
example/fine_advection/advection_package.hpp Show resolved Hide resolved
example/fine_advection/stokes.hpp Outdated Show resolved Hide resolved
example/fine_advection/stokes.hpp Show resolved Hide resolved
Comment on lines +276 to +293
if (cl == CellLevel::same) {
if (el == TE::CC) {
return cell_volume_;
} else if (el == TE::F1) {
return area_[X1DIR - 1];
} else if (el == TE::F2) {
return area_[X2DIR - 1];
} else if (el == TE::F3) {
return area_[X3DIR - 1];
} else if (el == TE::E1) {
return dx_[X1DIR - 1];
} else if (el == TE::E2) {
return dx_[X2DIR - 1];
} else if (el == TE::E3) {
return dx_[X3DIR - 1];
} else if (el == TE::NN) {
return 1.0;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this all new or can we call the older volume method which defaults to CellLevel::same?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the old Volume method is templated on the topological element. Here I added a new Volume overload that is not templated and takes a topological type and a cell level as an argument. It should give the same results as the templated volume function.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant was that for the CellLevel::same branch can you call the old method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could, but since the old one is templated on TE and this one is not it doesn't save any lines of code since you would have to call each template by hand. I am not actually sure that this really needs to be templates though.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. Could the old one optionally take a runtime? That might be useful...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think the best solution might be to have the old one just pass the template argument as a regular argument to the new one and have the new one have a default argument of cell level same. I doubt that has any performance impact.

src/interface/sparse_pack.hpp Show resolved Hide resolved
src/mesh/mesh.cpp Show resolved Hide resolved
@lroberts36 lroberts36 mentioned this pull request May 29, 2024
13 tasks
Copy link
Collaborator

@pgrete pgrete left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Thanks for putting the extra effort in to make it (almost) feature complete.
I just got a few minor comments.

example/fine_advection/CMakeLists.txt Outdated Show resolved Hide resolved
Comment on lines +89 to +90
auto start_send = tl.AddTask(none, parthenon::StartReceiveBoundaryBuffers, mc1);
auto start_flxcor = tl.AddTask(none, parthenon::StartReceiveFluxCorrections, mc0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent of this PR but relevant in the context of recent discussion around exhausting MPI limits, it might be worth to change the pattern here to first start all receives (in their own TaskRegion) rather than starting them "per pack" as the behavior will then depend on the pack size.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that seems reasonable.

example/fine_advection/advection_driver.cpp Show resolved Hide resolved
example/fine_advection/parthinput.advection Outdated Show resolved Hide resolved
example/fine_advection/advection_driver.cpp Show resolved Hide resolved
example/fine_advection/stokes.hpp Show resolved Hide resolved
src/bvals/boundary_conditions_generic.hpp Show resolved Hide resolved
Comment on lines +221 to +238
pmb->par_for_bndry(
PARTHENON_AUTO_LABEL, nb, domain, el, coarse, fine,
KOKKOS_LAMBDA(const int &l, const int &k, const int &j, const int &i) {
if (TYPE == BCType::Reflect) {
const bool reflect = (q(b, el, l).vector_component == DIR);
q(b, el, l, k, j, i) =
(reflect ? -1.0 : 1.0) * q(b, el, l, X3 ? offset - k : k,
X2 ? offset - j : j, X1 ? offset - i : i);
} else if (TYPE == BCType::FixedFace) {
q(b, el, l, k, j, i) =
2.0 * val - q(b, el, l, X3 ? offset - k : k, X2 ? offset - j : j,
X1 ? offset - i : i);
} else if (TYPE == BCType::ConstantDeriv) {
Real dq = q(b, el, l, X3 ? ref + offsetin : k, X2 ? ref + offsetin : j,
X1 ? ref + offsetin : i) -
q(b, el, l, X3 ? ref - offsetout : k, X2 ? ref - offsetout : j,
X1 ? ref - offsetout : i);
Real delta = 0.0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the complexity of this code (and above in this file) is it worth to update the new test case for use of non-periodic boundary conditions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I think we want test coverage for all types of boundary conditions, different forest configurations, sparse and non-sparse, and regular and fine fields. Once the rest of these PRs that rely on this one are in, I was going to make another PR adding regression tests, add gold files, and maybe remove the old sparse advection test.

}
} else if (cl == CellLevel::fine) {
if (el == TE::CC) {
return cell_volume_ / 8.0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this generally true (i.e., design decision) for <3D sims?
I don't recall how we handle this right now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that how we deal with, e.g., 2D simulations is that they are actually 3D (so the volume of a cell is a 3-volume) but we just assume they have translational symmetry in the z-direction. In that case, I think dividing by 8 here for all ndim is the right thing to do.

Comment on lines 2 to 4
# Athena++ astrophysical MHD code
# Copyright(C) 2014 James M. Stone <jmstone@princeton.edu> and other code contributors
# Licensed under the 3-clause BSD License, see LICENSE file for details
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> Parthenon

@lroberts36 lroberts36 disabled auto-merge June 13, 2024 18:25
@lroberts36 lroberts36 disabled auto-merge June 13, 2024 19:41
@lroberts36 lroberts36 merged commit f3916be into develop Jun 13, 2024
51 of 54 checks passed
@BenWibking
Copy link
Collaborator

This broke the existing use of pmb->par_for_bndry(...) in AthenaPK. It looks like this was missed from the "breaking changes" section of the changelog.

If we are not using fine fields, should the fine argument of par_for_bndry always be false?

@BenWibking BenWibking changed the title Add fine field option [Breaking change] Add fine field option Jun 18, 2024
@lroberts36
Copy link
Collaborator Author

@BenWibking: Yes, the fine argument should just be set to false. Sorry, I included the breaks-downstream label but I guess forgot to put this in the correct section of changelog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants